package com.ideal.frame;

import com.ideal.frame.runner.RootNodeRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.client.RestTemplate;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.nio.charset.StandardCharsets;
import java.util.Collections;

/**
 * @Author: jindong
 * @Description: 服务启动类
 * @Date: 10:25 2020/02/05
 */
@EnableAspectJAutoProxy(exposeProxy = true)
@SpringBootApplication
@ServletComponentScan
@EnableSwagger2
@EnableScheduling
public class MaisServerApplication {

    public static void main(String[] args) {
        ApplicationContext context = SpringApplication.run(MaisServerApplication.class, args);
        context.getBean(RootNodeRunner.class).runSync();
    }

    @Bean
    public RestTemplate restTemplate() {
        RestTemplate restTemplate = new RestTemplate();
        restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
        return restTemplate;
    }
}
